#pragma once

/*
 * anet asio defining header.
 */

#include <functional>
#include "asio.hpp"
#include <assert.h>
#include <string>
#include <stdarg.h>
#include <stdio.h>
#include <ctime>
#include <vector>
#if defined(WIN32)
  #pragma warning(disable:4996)
#endif

namespace anet {
	namespace tcp {
		class CConnection;

		// sleep ms.
        #define sleepMS(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))

		// sleep us.
        #define sleepUS(x) std::this_thread::sleep_for(std::chrono::microseconds(x))

		// asio library define.
		typedef asio::io_context asioIOContext;
		typedef asio::ip::tcp::acceptor asioAcceptor;
		typedef asio::ip::tcp::socket asioSocket;
		typedef asio::ip::tcp::endpoint asioEndPoint;

		// CConnection share pointer.
		typedef std::shared_ptr<CConnection> connSharePtr;

		// CConnection weak pointer.
		typedef std::weak_ptr<CConnection> connWeakPtr;

		// async_connect error callback.
		typedef std::function<void(const char* ip, unsigned short port, int err)> connectErrCallback;

		// write buffer max size;
		static int gMaxWriteBuffLength = 10 * 1024;

		// max read buffer size;
		static int gMaxReadBuffLength = 10 * 1024;

		// max packet size.
		static int gMaxPacketSize = 10 * 1024;

		// listen blog size
		static int gMaxListenBlog = 128;

		// set max packet size
		inline void setMaxPacketSize(int maxPacketSize) {
			if (maxPacketSize > 0) {
				gMaxPacketSize = maxPacketSize;
			}
		}

		// set max listen blog size
		inline void setMaxListenBlogSize(int blogSize) {
			if (blogSize > 0) {
				gMaxListenBlog = blogSize;
			}
		}

		// set reading buffer size
		inline void setReadBufferSize(int readBufferSize) {
			if (readBufferSize > 0) {
				gMaxReadBuffLength = readBufferSize;
			}
		}

		// set writing buffer size
		inline void setWriteBufferSize(int writeBufferSize) {
			if (writeBufferSize > 0) {
				gMaxWriteBuffLength = writeBufferSize;
			}
		}
	}
}